package com.platform.service.impl;

import com.platform.cache.J2CacheUtils;
import com.platform.dao.UpperBoundConfigDao;
import com.platform.entity.UpperBoundConfigEntity;
import com.platform.service.UpperBoundConfigService;
import com.platform.util.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Service实现类
 *
 * @author lipengjun
 * @email 939961241@qq.com
 * @date 2019-02-20 16:15:57
 */
@Service("tUpperBoundConfigService")
public class UpperBoundConfigServiceImpl implements UpperBoundConfigService {
    @Autowired
    private UpperBoundConfigDao tUpperBoundConfigDao;

    @Override
    public UpperBoundConfigEntity queryObject(Long id) {
        return tUpperBoundConfigDao.queryObject(id);
    }

    @Override
    public List<UpperBoundConfigEntity> queryList(Map<String, Object> map) {
        return tUpperBoundConfigDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return tUpperBoundConfigDao.queryTotal(map);
    }

    @Override
    public int save(UpperBoundConfigEntity tUpperBoundConfig) {
        J2CacheUtils.clear(Constants.REDIS_UPPER_KEY);

        Integer userId = tUpperBoundConfig.getUserId();
        if(userId != null && !userId.equals("")){
            tUpperBoundConfig.setType(userId);
        }
        return tUpperBoundConfigDao.save(tUpperBoundConfig);
    }

    @Override
    public int update(UpperBoundConfigEntity tUpperBoundConfig) {
        J2CacheUtils.clear(Constants.REDIS_UPPER_KEY);

        Integer userId = tUpperBoundConfig.getUserId();
        if(userId != null && !userId.equals("")){
            tUpperBoundConfig.setType(userId);
        }

        return tUpperBoundConfigDao.update(tUpperBoundConfig);
    }

    @Override
    public int delete(Long id) {
        J2CacheUtils.clear(Constants.REDIS_UPPER_KEY);
        return tUpperBoundConfigDao.delete(id);
    }

    @Override
    public int deleteBatch(Long[] ids) {
        J2CacheUtils.clear(Constants.REDIS_UPPER_KEY);
        return tUpperBoundConfigDao.deleteBatch(ids);
    }
}
